<template>
  <div>
  <p>
  <br>
  <br>
  <br>
<!--   <p> -->
<!-- payload -->
<!-- {{this.wepayload}} -->
<!--   </p> -->
<!--   <p> -->
<!--   Lepay -->
<!-- {{this.Lepay}} -->
<!--   </p> -->
  <div class="paying">
    <h1 class="title">支付中，请稍后</h1>
  </div>
</div>
</template>
</html>
<script type="text/javascript">

export default {
  data() {
    return {
       wepayload:{
         actionName: "LePay",
         url:'lepay',
         postData: {
      			"orderId":'',
            "name":"knowledge",
            "catCode":"1",
            "device":"3",
            "payType":"3",
            "amount":"",
            "openid": ""
      	   // "appId":Appid, //   "timeStamp":Timestamp, //   "nonceStr":Noncestr, //   "package":Pkg, //   "signType":"MD5", //   "paySign":Sign }
       }
      }
    }
  },
  created(){
    // https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxf915dbfb1b2c6ab8&redirect_uri=http%3A%2F%2Fwx.lep365.com%2FWeChat%2Fst%2FsnsapiBase&response_type=code&scope=snsapi_base&state=kcgm&connect_redirect=1#wechat_redirect
    if (this.$route.params.openId != 1234) {
      this.wepayload.postData.orderId = window.localStorage.getItem('setorderid')
      this.wepayload.postData.amount = window.localStorage.getItem('setmount')
      this.wepayload.postData.openid = this.$route.params.openId ;
       this.$store.commit('restful_api',this.wepayload)
    }else {
      window.localStorage.setItem('setorderid',this.$route.params.orderId)
      window.localStorage.setItem('setmount',this.$route.params.totalprice)
      this.wepayload.postData.orderId= this.$route.params.orderId
      this.wepayload.postData.amount= this.$route.params.totalprice
    }

    var x = this.$route.params.orderId ;
    if (this.wepayload.postData.openid =='') {
        window.location.href='http://m.lep365.com/get-weixin-code.html?appid=wxf915dbfb1b2c6ab8&scope=snsapi_base&state=kcgm'
    }else {
      this.wepayload.postData.openid = this.$route.params.openId
      setTimeout(function () {
        this.wechat()
      }.bind(this), 500);
    }
      // this.wepayload.orderId = this.$route.params.orderId
  },
  computed :{
    Lepay(){
    var x = this.$store.getters.all_restful_LePay
      if(x){
        return x
      }
    }
  },
  methods:{
     wechat(){
       var xx = this.Lepay;
     if (xx) {
      function onBridgeReady(){
         WeixinJSBridge.invoke(
                'getBrandWCPayRequest', {
                  "appId":xx.body.appid,
                  "timeStamp":xx.body.timestamp,
                  "nonceStr":xx.body.noncestr,
                  "package":xx.body.pkg,
                  "signType":"MD5",
                  "paySign":xx.body.sign
                       },
                function(res){
                     if(res.err_msg == "get_brand_wcpay_request:ok" ) {
                       alert('here you go baby')
                     }     // 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回    ok，但并不保证它绝对可靠。
                    else{
                          alert('there you go you!!! ')
                          this.$vux.alert.show({
                            title:'支付结果',
                            content:'支付未完成:'+ res
                          })
                      }
                   }
            );
      }
      if (typeof WeixinJSBridge == "undefined"){
        alert('WeixinJSBridge undefined')
         if( document.addEventListener ){
                document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
            }else if (document.attachEvent){
                   document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
                   document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
               }
      }else{
        alert('esle go br ready')
         onBridgeReady();
      }

       // WeixinJSBridge.invoke(
       // 'getBrandWCPayRequest', {
       // });

     }
     // this.uname=GetQueryString("userName")
     }
  }


}

</script>
